package com.example.blogsystemssm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestRedis {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    private final String REDIS_KEY = "test_redis";

    @RequestMapping("/setstr")
    public String setStr(String key, String value) {
        if (StringUtils.hasLength(key) && StringUtils.hasLength(value)) {
            stringRedisTemplate.
                    opsForValue().
                    set(REDIS_KEY, "Test Input Redis Data");
            return "Redis操作成功";
        } else {
            return "操作失败, 请重试"  ;
        }
    }
}
